rm(list=ls()) #clear

library(psych)
library(ggplot2)
library(AER)
library(gridExtra)
library(estimatr)
library(summarytools)
library(tidyverse)
library(ggeffects)
library(sjPlot)
library(expss)
library(dotwhisker)
library(ggpubr)
library(dplyr)
library(plyr)
library(ggridges)
library(effects)
library(margins)
library(sandwich)
library(lavaan)
library(haven)
library(MASS)
library(GPArotation)
library(interactions)
library(hrbrthemes)
library(ggstance)
library(stargazer)
library(patchwork)
library(gtools)
library(modelsummary)
library(kableExtra)
library(broom)
library(RColorBrewer)
library(nnet)

load("Main Analyses/dataS1.RData")
load("Main Analyses/dataS2.RData")
load("Main Analyses/dataS3.RData")
load("Main Analyses/dataS4.RData")

# put datasets in a list object
df_list = mget(ls(pattern = "dat[0-4]"))

# split elements of above list by party
pt_list = lapply(df_list, function(x) split(x, x$pid01))

#Part II Regressions and Figures ################

  #### Partisan Social Identity ####

id1 <- lapply(df_list,
             function(x) broom::tidy(lm(idtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                            data = x, na.action = na.exclude))) 
id2 <- lapply(df_list,
             function(x) broom::tidy(lm(idtot~apstot9+age+ba+white+hisplat+male+inc,
                                        data = x, na.action = na.exclude))) 

id<- dplyr::bind_rows(c(id1,id2), .id = "study") %>%
  mutate(.,
            conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                                 2) * std.error,
            conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                                  2) * std.error
  )

id$fullscale<- ifelse(id$term == "apstot9", 0, 1)

id<- dplyr::filter(id, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

id<- relabel_predictors(id,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization")

id

fid<- ggplot(id, aes(x = estimate, 
                     xmin = conf.low, 
                     xmax = conf.high, 
                     y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("Full Scale", "Subdimensions"))~
               factor(study, labels = c("Study 1", "Study 2", "Study 3", "Study 4 W1")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Social Identity") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(breaks=c(0.0, 0.2, 0.4, 0.6, 0.8)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_text(size = 9),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

fid

#### Party ID Extremity ####

pidex1 <- lapply(df_list,
              function(x) broom::tidy(lm(rpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude))) 
pidex2 <- lapply(df_list,
              function(x) broom::tidy(lm(rpidex~apstot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude))) 

pidex<- dplyr::bind_rows(c(pidex1,pidex2), .id = "study") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  )

pidex$fullscale<- ifelse(pidex$term == "apstot9", 0, 1)

pidex<- dplyr::filter(pidex, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

pidex<- relabel_predictors(pidex,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization")

pidex

fpidex<- ggplot(pidex, aes(x = estimate, 
                        xmin = conf.low, 
                        xmax = conf.high, 
                        y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("Full Scale", "Subdimensions"))~
               factor(study, labels = c("Study 1", "Study 2", "Study 3", "Study 4 W1")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Identification Extremity") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(breaks=c(0.0, 0.2, 0.4, 0.6, 0.8, 1.0)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_text(size = 9),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

fpidex

#### Ideological Extremity ####

idex1 <- lapply(df_list,
                 function(x) broom::tidy(lm(ridex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 
idex2 <- lapply(df_list,
                 function(x) broom::tidy(lm(ridex~apstot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 

idex<- dplyr::bind_rows(c(idex1,idex2), .id = "study") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  )

idex$fullscale<- ifelse(idex$term == "apstot9", 0, 1)

idex<- dplyr::filter(idex, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

idex<- relabel_predictors(idex,
                           apstot9 = "APS",
                           otot9 = "Othering",
                           atot9 = "Aversion",
                           mtot9 = "Moralization")

idex

fidex<- ggplot(idex, aes(x = estimate, 
                       xmin = conf.low, 
                       xmax = conf.high, 
                       y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("Full Scale", "Subdimensions"))~
               factor(study, labels = c("Study 1", "Study 2", "Study 3", "Study 4 W1")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Ideological Identification Extremity") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(breaks=c(0.0, 0.2, 0.4, 0.6, 0.8)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_text(size = 9),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

fidex

#### Political Knowledge ####

pk1 <- lapply(df_list[c(3,4)],
                 function(x) broom::tidy(lm(pktot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 
pk2 <- lapply(df_list[c(3,4)],
                 function(x) broom::tidy(lm(pktot~apstot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 

pk<- dplyr::bind_rows(c(pk1,pk2), .id = "study") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  )

pk$fullscale<- ifelse(pk$term == "apstot9", 0, 1)

pk<- dplyr::filter(pk, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

pk<- relabel_predictors(pk,
                          apstot9 = "APS",
                          otot9 = "Othering",
                          atot9 = "Aversion",
                          mtot9 = "Moralization")

pk

fpk<- ggplot(pk, aes(x = estimate, 
                         xmin = conf.low, 
                         xmax = conf.high, 
                         y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("Full Scale Model", "Subdimension Model"))~
               factor(study, labels = c("Study 3", "Study 4 W1")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Political Knowledge") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(breaks=c(-0.3, -0.2, -0.1,  0.0, 0.1, 0.2)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_text(size = 9),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

fpk

#### Warmth Bias ####

wb1 <- lapply(df_list[c(2,3,4)],
                 function(x) broom::tidy(lm(wbias~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 
wb2 <- lapply(df_list[c(2,3,4)],
                 function(x) broom::tidy(lm(wbias~apstot9+age+ba+white+hisplat+male+inc,
                                            data = x, na.action = na.exclude))) 

wb<- dplyr::bind_rows(c(wb1,wb2), .id = "study") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  )

wb$fullscale<- ifelse(wb$term == "apstot9", 0, 1)

wb<- dplyr::filter(wb, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

wb<- relabel_predictors(wb,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization")

wb

fwb<- ggplot(wb, aes(x = estimate, 
                     xmin = conf.low, 
                     xmax = conf.high, 
                     y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("FS Model", "Subdimension Model"))~
               factor(study, labels = c("Study 2", "Study 3", "Study 4 W1")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Warmth Bias") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(limits = c(-0.1, 0.8), breaks=c(0.0, 0.2, 0.4, 0.6, 0.8)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_text(size = 9),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

fwb

#### Trait Ratings ####

tr1 <- lapply(df_list[c(2,3)],
              function(x) broom::tidy(lm(trtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude))) 
tr2 <- lapply(df_list[c(2,3)],
              function(x) broom::tidy(lm(trtot~apstot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude))) 

tr<- dplyr::bind_rows(c(tr1,tr2), .id = "study") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  )

tr$fullscale<- ifelse(tr$term == "apstot9", 0, 1)

tr<- dplyr::filter(tr, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9")

tr<- relabel_predictors(tr,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization")

tr

ftr<- ggplot(tr, aes(x = estimate, 
                     xmin = conf.low, 
                     xmax = conf.high, 
                     y = factor(term, levels = c("Moralization", "Aversion", "Othering", "APS")))) + 
  geom_pointrangeh(size = .4, fatten = .5) + 
  facet_grid(factor(fullscale, labels = c("Full Scale", "Subdimensions"))~
               factor(study, labels = c("Study 2", "Study 3")),
             scales = c("free_y"),
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Trait Rating Bias") +
  xlab("") + 
  ylab("") + 
  scale_x_continuous(breaks=c(0.0, 0.2, 0.4, 0.6, 0.8)) +
  theme(
    plot.title = element_text(hjust = .5, size = 10, face = "plain"),
    axis.text.x = element_text(size = 9),
    axis.text.y = element_blank(),
    strip.text = element_text(size = 9),
    strip.text.y = element_blank())

ftr

#### Figure 1 ####

Figure1<- fpidex / fid / fidex / (fpk + ftr) / fwb

Figure1

ggsave("Plots/Figure1.pdf",
       plot = Figure1,
       width = 8,
       height = 10,
       dpi = 1000,
       units = "in")

#Figure1<- fpidex / fidex / fid 

#Figure1

#ggsave("Plots/Figure1.pdf",
#       plot = Figure1,
#       width = 7,
#       height = 6,
#       dpi = 300,
#       units = "in")

#Figure2<- (fpk + ftr) / fwb

#Figure2

#ggsave("Plots/Figure2.pdf",
#       plot = Figure2,
#       width = 8,
#       height = 5,
#       dpi = 300,
#       units = "in")

#Part III Regressions and Figures #################

#### Support Anti-Democratic Actions ####

var_list = list(dat3$ANESdnorm, dat3$uncandtot, dat3$pspitetot, dat3$artot)

#anti1 <- lapply(df_list[c(2,3)],
#                function(x) broom::tidy(lm(rotgtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                           data = x, na.action = na.exclude)))
anti3 <- lapply(df_list[c(2,3)],
                function(x) broom::tidy(lm(rotgtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                           data = x, na.action = na.exclude)))

#anti5 <- lapply(df_list[c(2,3)],
#                function(x) broom::tidy(lm(rotgtot~apstot9+age+ba+white+hisplat+male+inc,
#                                           data = x, na.action = na.exclude)))

anti7<- lapply(df_list[c(2,3)],
                function(x) broom::tidy(lm(rotgtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                           data = x, na.action = na.exclude))) 

#anti2 <- lapply(var_list,
#                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                            data = dat3, na.action = na.exclude))) 

anti4 <- lapply(var_list,
                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = dat3, na.action = na.exclude)))

#anti6 <- lapply(var_list,
#                 function(x) broom::tidy(lm(x~apstot9+age+ba+white+hisplat+male+inc,
#                                            data = dat3, na.action = na.exclude))) 

anti8 <- lapply(var_list,
                 function(x) broom::tidy(lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = dat3, na.action = na.exclude))) 

antidem<- dplyr::bind_rows(c(anti3, anti4, anti7, anti8), .id = "model") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  ) 

antidem<- dplyr::filter(antidem, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9" | term == "wbias")

antidem<- relabel_predictors(antidem,
                           apstot9 = "APS",
                           otot9 = "Othering",
                           atot9 = "Aversion",
                           mtot9 = "Moralization",
                           wbias = "Warmth Bias")

#antidem$full<- ifelse(antidem$model == 13 |
#                      antidem$model == 14 | 
#                      antidem$model == 15 |
#                      antidem$model == 16 | 
#                      antidem$model == 17 | 
#                      antidem$model == 18 | 
#                      antidem$model == 19 | 
#                      antidem$model == 20 | 
#                      antidem$model == 21 | 
#                      antidem$model == 22 | 
#                      antidem$model == 23 | 
#                      antidem$model == 24, 0, 1)

antidem$full<- ifelse(antidem$model == 7 |
                      antidem$model == 8 |  
                      antidem$model == 9 |
                      antidem$model == 10 |
                      antidem$model == 11 |
                      antidem$model == 12, 1, 0)

#antidem$comp<- ifelse(antidem$model == 7 |
#                      antidem$model == 8 | 
#                      antidem$model == 9 |
#                      antidem$model == 10 | 
#                      antidem$model == 11 | 
#                      antidem$model == 12 | 
#                      antidem$model == 19 | 
#                      antidem$model == 20 | 
#                      antidem$model == 21 | 
#                      antidem$model == 22 | 
#                      antidem$model == 23 | 
#                      antidem$model == 24, 1, 0)

#antidem$dv<- ifelse(antidem$model == 1 | 
#                    antidem$model == 7 | 
#                    antidem$model == 13 | 
#                    antidem$model == 19, "rotg1",
#                  ifelse(antidem$model == 2 | 
#                           antidem$model == 8 | 
#                           antidem$model == 14 | 
#                           antidem$model == 20, "rotg2",
#                         ifelse(antidem$model == 3 | 
#                                  antidem$model == 9 | 
#                                  antidem$model == 15 | 
#                                  antidem$model == 21, "anes",
#                                ifelse(antidem$model == 4 | 
#                                         antidem$model == 10 | 
#                                         antidem$model == 16 | 
#                                         antidem$model == 22, "uncand",
#                                       ifelse(antidem$model == 5 | 
#                                                antidem$model == 11 | 
#                                                antidem$model == 17 | 
#                                                antidem$model == 23, "pspite",
#                                              ifelse(antidem$model == 6 | 
#                                                       antidem$model == 12 | 
#                                                       antidem$model == 18 | 
#                                                       antidem$model == 24, "ar", antidem$model))))))

antidem$dv<- ifelse(antidem$model == 1 | antidem$model == 7, "rotg1",
                    ifelse(antidem$model == 2 | antidem$model == 8, "rotg2",
                           ifelse(antidem$model == 3 | antidem$model == 9, "anes",
                                  ifelse(antidem$model == 4 | antidem$model == 10, "uncand",
                                         ifelse(antidem$model == 5 | antidem$model == 11, "pspite",
                                                ifelse(antidem$model == 6 | antidem$model == 12, "ar", antidem$model))))))

antidem

rotg<- subset(antidem, antidem$dv=="rotg1" | antidem$dv=="rotg2")

frotg<- ggplot(rotg, aes(x = estimate, 
                           xmin = conf.low, 
                           xmax = conf.high, 
                           y = factor(term, levels = c("Warmth Bias",
                                                       "Moralization",
                                                       "Aversion",
                                                       "Othering",
                                                       "APS")))) +
 #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(dv, labels = c("Study 2", "Study 3")),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Rules of the Game") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_text(size = 7),
    strip.text.y = element_blank()
#    legend.key.size = unit(.6,"cm"),
#    legend.key = element_rect(fill = "white"),
#    legend.position = "bottom",
#    legend.title = element_blank(),
#    legend.text = element_text(size = 7),
#    legend.box.spacing = unit(0, "pt")) +
#  scale_shape_manual(
#    name = "Model",
#    breaks = c(0,1),
#    labels = c("No Warmth Bias", "Warmth Bias"),
#    values = c(16, 17)
  ) 

frotg

dnorms<- subset(antidem, antidem$dv=="anes")

fdnorms<- ggplot(dnorms, aes(x = estimate, 
                         xmin = conf.low, 
                         xmax = conf.high, 
                         y = factor(term, levels = c("Warmth Bias",
                                                     "Moralization",
                                                     "Aversion",
                                                     "Othering",
                                                     "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Democratic Norms (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

fdnorms

anticand<- subset(antidem, antidem$dv=="uncand")

fanticand<- ggplot(anticand, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Vote for Anti-Democratic Candidate (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

fanticand

pspite<- subset(antidem, antidem$dv=="pspite")

fpspite<- ggplot(pspite, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Spite (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

fpspite

ar<- subset(antidem, antidem$dv=="ar")

far<- ggplot(ar, aes(x = estimate, 
                                 xmin = conf.low, 
                                 xmax = conf.high, 
                                 y = factor(term, levels = c("Warmth Bias",
                                                             "Moralization",
                                                             "Aversion",
                                                             "Othering",
                                                             "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Support for Authoritarian Rule (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

far

#### Violence ####

#pv1 <- lapply(df_list[c(2,4)],
#              function(x) broom::tidy(lm(pvtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                         data = x, na.action = na.exclude))) 
#pv1<- list(dplyr::bind_rows(c(pv1), .id = "model"))

pv2 <- lapply(df_list[c(2,4)],
              function(x) broom::tidy(lm(pvtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude)))
pv2<- list(dplyr::bind_rows(c(pv2), .id = "model"))

#pv3 <- lapply(df_list[c(2,4)],
#              function(x) broom::tidy(lm(pvtot~apstot9+age+ba+white+hisplat+male+inc,
#                                         data = x, na.action = na.exclude)))
#pv3<- list(dplyr::bind_rows(c(pv3), .id = "model"))

pv4 <- lapply(df_list[c(2,4)],
              function(x) broom::tidy(lm(pvtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                        data = x, na.action = na.exclude)))
pv4<- list(dplyr::bind_rows(c(pv4), .id = "model"))



pv<- dplyr::bind_rows(c(pv2,pv4), .id = "submodel") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  ) 

pv<- dplyr::filter(pv, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9" | term == "wbias")

pv<- relabel_predictors(pv,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization",
                        wbias = "Warmth Bias")

pv$full<- ifelse(pv$submodel == "2", 1, 0)

#pv$comp<- ifelse(pv$submodel == 2 | 
#                   pv$submodel == 4, 1, 0)

pv

partypv<- subset(pv, pv$model=="dat2")

fpartypv<- ggplot(partypv, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(model),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Violence (Study 2)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

fpartypv

genpv<- subset(pv, pv$model=="dat4")

fgenpv<- ggplot(genpv, aes(x = estimate, 
                                 xmin = conf.low, 
                                 xmax = conf.high, 
                                 y = factor(term, levels = c("Warmth Bias",
                                                             "Moralization",
                                                             "Aversion",
                                                             "Othering",
                                                             "APS")))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .8), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(1,0))~
               factor(model),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("General Political Violence (Study 4 W1)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank()
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) 

fgenpv

#### Figure 2 ####

Figure2<- frotg / (fdnorms + fanticand) / (fpspite + far) / (fpartypv + fgenpv) 

Figure2

ggsave("Plots/Figure2.pdf",
       plot = Figure2,
       width = 7,
       height = 9.5,
       dpi = 1000,
       units = "in")

#Part III Regressions by Party  #########################

#rotg1 <- lapply(pt_list[c(2,3)], lapply,
#                function(x) broom::tidy(lm(rotgtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                           data = x, na.action = na.exclude)))

rotg2 <- lapply(pt_list[c(2,3)], lapply,
                function(x) broom::tidy(lm(rotgtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                           data = x, na.action = na.exclude)))

#rotg3 <- lapply(pt_list[c(2,3)], lapply,
#                function(x) broom::tidy(lm(rotgtot~apstot9+age+ba+white+hisplat+male+inc,
#                                           data = x, na.action = na.exclude)))

rotg4 <- lapply(pt_list[c(2,3)], lapply,
                function(x) broom::tidy(lm(rotgtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                           data = x, na.action = na.exclude)))


lister<- c(1, 2)
#rotg1<- lapply(lister,
#               function(x) dplyr::bind_rows(rotg1[[x]][["0"]], rotg1[[x]][["1"]],
#                                            .id = "party"))

#rotg1[[1]]<- mutate(rotg1[[1]], comp = "0")
#rotg1[[2]]<- mutate(rotg1[[2]], comp = "0")
#rotg1[[1]]<- mutate(rotg1[[1]], full = "1")
#rotg1[[2]]<- mutate(rotg1[[2]], full = "1")

#names(rotg1)<- c("rotg1", "rotg2")

rotg2<- lapply(lister,
               function(x) dplyr::bind_rows(rotg2[[x]][["0"]], rotg2[[x]][["1"]],
                                            .id = "party"))

#rotg2[[1]]<- mutate(rotg2[[1]], comp = "1")
#rotg2[[2]]<- mutate(rotg2[[2]], comp = "1")
rotg2[[1]]<- mutate(rotg2[[1]], full = "1")
rotg2[[2]]<- mutate(rotg2[[2]], full = "1")

names(rotg2)<- c("rotg1", "rotg2")

#rotg3<- lapply(lister,
#               function(x) dplyr::bind_rows(rotg3[[x]][["0"]], rotg3[[x]][["1"]],
#                                            .id = "party"))

#rotg3[[1]]<- mutate(rotg3[[1]], comp = "0")
#rotg3[[2]]<- mutate(rotg3[[2]], comp = "0")
#rotg3[[1]]<- mutate(rotg3[[1]], full = "0")
#rotg3[[2]]<- mutate(rotg3[[2]], full = "0")

#names(rotg3)<- c("rotg1", "rotg2")

rotg4<- lapply(lister,
               function(x) dplyr::bind_rows(rotg4[[x]][["0"]], rotg4[[x]][["1"]],
                                            .id = "party"))

#rotg4[[1]]<- mutate(rotg4[[1]], comp = "1")
#rotg4[[2]]<- mutate(rotg4[[2]], comp = "1")
rotg4[[1]]<- mutate(rotg4[[1]], full = "0")
rotg4[[2]]<- mutate(rotg4[[2]], full = "0")

names(rotg4)<- c("rotg1", "rotg2")


ptvar_list = split(dat3[c("ANESdnorm", "uncandtot", "pspitetot", "artot")],
                   dat3$pid01)

#antipt1 <- lapply(ptvar_list[["0"]], 
#                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                            data = subset(dat3, dat3$pid01==0),
#                                            na.action = na.exclude)) %>%
#                   mutate(., party = "1",
#                          comp = "0",
#                          full = "1"))

antipt2 <- lapply(ptvar_list[["0"]], 
                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = subset(dat3, dat3$pid01==0),
                                            na.action = na.exclude)) %>%
                   mutate(., party = "1",
                          #comp = "1",
                          full = "1"))

#antipt3 <- lapply(ptvar_list[["1"]], 
#                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                            data = subset(dat3, dat3$pid01==1),
#                                            na.action = na.exclude)) %>%
#                   mutate(., party = "2",
#                          comp = "0",
#                          full = "1"))

antipt4 <- lapply(ptvar_list[["1"]], 
                 function(x) broom::tidy(lm(x~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = subset(dat3, dat3$pid01==1),
                                            na.action = na.exclude)) %>%
                   mutate(., party = "2",
                          #comp = "1",
                          full = "1"))

#antipt5 <- lapply(ptvar_list[["0"]], 
#                 function(x) broom::tidy(lm(x~apstot9+age+ba+white+hisplat+male+inc,
#                                            data = subset(dat3, dat3$pid01==0),
#                                            na.action = na.exclude)) %>%
#                   mutate(., party = "1",
#                          comp = "0",
#                          full = "0"))

antipt6 <- lapply(ptvar_list[["0"]], 
                 function(x) broom::tidy(lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = subset(dat3, dat3$pid01==0),
                                            na.action = na.exclude)) %>%
                   mutate(., party = "1",
                          #comp = "1",
                          full = "0"))

#antipt7 <- lapply(ptvar_list[["1"]], 
#                 function(x) broom::tidy(lm(x~apstot9+age+ba+white+hisplat+male+inc,
#                                            data = subset(dat3, dat3$pid01==1),
#                                            na.action = na.exclude)) %>%
#                   mutate(., party = "2",
#                          comp = "0",
#                          full = "0"))

antipt8 <- lapply(ptvar_list[["1"]], 
                 function(x) broom::tidy(lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                            data = subset(dat3, dat3$pid01==1),
                                            na.action = na.exclude)) %>%
                   mutate(., party = "2",
                          #comp = "1",
                          full = "0"))

antipt<- dplyr::bind_rows(c(rotg2, rotg4,
                           antipt2, antipt4,
                           antipt6, antipt8), .id = "dv") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error
  ) 

antipt<- dplyr::filter(antipt, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9" | term == "wbias")

antipt<- relabel_predictors(antipt,
                           apstot9 = "APS",
                           otot9 = "Othering",
                           atot9 = "Aversion",
                           mtot9 = "Moralization",
                           wbias = "Warmth Bias")

antipt


rotgpt<- subset(antipt, antipt$dv=="rotg1" | antipt$dv=="rotg2")

frotgpt<- ggplot(rotgpt, aes(x = estimate, 
                         xmin = conf.low, 
                         xmax = conf.high, 
                         y = factor(term, levels = c("Warmth Bias",
                                                     "Moralization",
                                                     "Aversion",
                                                     "Othering",
                                                     "APS")),
                         color = as.factor(party),
                         shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv, labels = c("Study 2", "Study 3")),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Rules of the Game") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_text(size = 7),
    strip.text.y = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

anespt<- subset(antipt, antipt$dv=="ANESdnorm")

fanespt<- ggplot(anespt, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")),
                             color = as.factor(party),
                             shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Democratic Norms (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

fanespt

anticandpt<- subset(antipt, antipt$dv=="uncandtot")

fanticandpt<- ggplot(anticandpt, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")),
                             color = as.factor(party),
                             shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Vote for Anti-Democratic Candidate (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

fanticandpt

pspitept<- subset(antipt, antipt$dv=="pspitetot")

fpspitept<- ggplot(pspitept, aes(x = estimate, 
                             xmin = conf.low, 
                             xmax = conf.high, 
                             y = factor(term, levels = c("Warmth Bias",
                                                         "Moralization",
                                                         "Aversion",
                                                         "Othering",
                                                         "APS")),
                             color = as.factor(party),
                             shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Spite (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

fpspitept

arpt<- subset(antipt, antipt$dv=="artot")

farpt<- ggplot(arpt, aes(x = estimate, 
                                 xmin = conf.low, 
                                 xmax = conf.high, 
                                 y = factor(term, levels = c("Warmth Bias",
                                                             "Moralization",
                                                             "Aversion",
                                                             "Othering",
                                                             "APS")),
                                 color = as.factor(party),
                                 shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Support for Authoritarian Rule (Study 3)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

farpt

## Violence Party ##

#pvpt1 <- lapply(pt_list[c(2,4)], lapply,
#              function(x) broom::tidy(lm(pvtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
#                                         data = x, na.action = na.exclude))) 

pvpt2 <- lapply(pt_list[c(2,4)], lapply,
              function(x) broom::tidy(lm(pvtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude)))

#pvpt3 <- lapply(pt_list[c(2,4)], lapply,
#              function(x) broom::tidy(lm(pvtot~apstot9+age+ba+white+hisplat+male+inc,
#                                         data = x, na.action = na.exclude)))

pvpt4 <- lapply(pt_list[c(2,4)], lapply,
              function(x) broom::tidy(lm(pvtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude)))

lister<- c(1, 2)
#pvpt1<- lapply(lister,
#             function(x) dplyr::bind_rows(pvpt1[[x]][["0"]], pvpt1[[x]][["1"]],
#                                          .id = "party"))
#pvpt1[[1]]<- mutate(pvpt1[[1]], comp = "0")
#pvpt1[[2]]<- mutate(pvpt1[[2]], comp = "0")
#pvpt1[[1]]<- mutate(pvpt1[[1]], full = "1")
#pvpt1[[2]]<- mutate(pvpt1[[2]], full = "1")

#names(pvpt1)<- c("dat2", "dat4")

pvpt2<- lapply(lister,
             function(x) dplyr::bind_rows(pvpt2[[x]][["0"]], pvpt2[[x]][["1"]],
                                          .id = "party"))
#pvpt2[[1]]<- mutate(pvpt2[[1]], comp = "1")
#pvpt2[[2]]<- mutate(pvpt2[[2]], comp = "1")
pvpt2[[1]]<- mutate(pvpt2[[1]], full = "1")
pvpt2[[2]]<- mutate(pvpt2[[2]], full = "1")

names(pvpt2)<- c("dat2", "dat4")

#pvpt3<- lapply(lister,
#             function(x) dplyr::bind_rows(pvpt3[[x]][["0"]], pvpt3[[x]][["1"]],
#                                          .id = "party"))
#pvpt3[[1]]<- mutate(pvpt3[[1]], comp = "0")
#pvpt3[[2]]<- mutate(pvpt3[[2]], comp = "0")
#pvpt3[[1]]<- mutate(pvpt3[[1]], full = "0")
#pvpt3[[2]]<- mutate(pvpt3[[2]], full = "0")

#names(pvpt3)<- c("dat2", "dat4")

pvpt4<- lapply(lister,
             function(x) dplyr::bind_rows(pvpt4[[x]][["0"]], pvpt4[[x]][["1"]],
                                          .id = "party"))
#pvpt4[[1]]<- mutate(pvpt4[[1]], comp = "1")
#pvpt4[[2]]<- mutate(pvpt4[[2]], comp = "1")
pvpt4[[1]]<- mutate(pvpt4[[1]], full = "0")
pvpt4[[2]]<- mutate(pvpt4[[2]], full = "0")

names(pvpt4)<- c("dat2", "dat4")

pvpt<- dplyr::bind_rows(c(pvpt2, pvpt4), .id = "dv") %>%
  mutate(.,
            conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                                 2) * std.error,
            conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                                  2) * std.error
  ) 

pvpt<- dplyr::filter(pvpt, term == "apstot9" | term == "otot9" | term == "atot9" | term == "mtot9" | term == "wbias")

pvpt<- relabel_predictors(pvpt,
                        apstot9 = "APS",
                        otot9 = "Othering",
                        atot9 = "Aversion",
                        mtot9 = "Moralization",
                        wbias = "Warmth Bias")

pvpt

partypvpt<- subset(pvpt, pvpt$dv=="dat2")

fpartypvpt<- ggplot(partypvpt, aes(x = estimate, 
                         xmin = conf.low, 
                         xmax = conf.high, 
                         y = factor(term, levels = c("Warmth Bias",
                                                     "Moralization",
                                                     "Aversion",
                                                     "Othering",
                                                     "APS")),
                         color = as.factor(party),
                         shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Partisan Violence (Study 2)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

fpartypvpt

genpvpt<- subset(pvpt, pvpt$dv=="dat4")

fgenpvpt<- ggplot(genpvpt, aes(x = estimate, 
                                   xmin = conf.low, 
                                   xmax = conf.high, 
                                   y = factor(term, levels = c("Warmth Bias",
                                                               "Moralization",
                                                               "Aversion",
                                                               "Othering",
                                                               "APS")),
                                   color = as.factor(party),
                                   shape = as.factor(party))) +
  #                          shape = as.factor(comp)))  
  geom_pointrangeh(position = position_dodge(width = .7), size = .5, fatten = 3) + 
  facet_grid(factor(full)~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("General Political Violence (Study 4 W1)") +
  xlab("") + 
  ylab("") + 
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.position = "bottom",
    legend.title = element_blank(),
    legend.text = element_text(size = 7),
    legend.box.spacing = unit(0, "pt")
    #    legend.key.size = unit(.6,"cm"),
    #    legend.key = element_rect(fill = "white"),
    #    legend.position = "bottom",
    #    legend.title = element_blank(),
    #    legend.text = element_text(size = 7),
    #    legend.box.spacing = unit(0, "pt")) +
    #  scale_shape_manual(
    #    name = "Model",
    #    breaks = c(0,1),
    #    labels = c("No Warmth Bias", "Warmth Bias"),
    #    values = c(16, 17)
  ) +
  scale_color_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c("blue", "red")
  ) +
  scale_shape_manual(
    name = "Model",
    breaks = c(1,2),
    labels = c("Democrat", "Republican"),
    values = c(15, 17)
  )

fgenpvpt

#### Figure 3 ####

Figure3<- frotgpt / (fanespt + fanticandpt) / (fpspitept + farpt) / (fpartypvpt + fgenpvpt) + plot_layout(guides = "collect") & 
  theme(legend.position = "bottom",
        legend.box.spacing = unit(0, "pt")) &
  guides(color = guide_legend(reverse = T),
         shape = guide_legend(reverse = T))

Figure3

ggsave("Plots/Figure3.pdf",
       plot = Figure3,
       width = 7,
       height = 10,
       dpi = 1000,
       units = "in")

# Westwood et al. Replication Experiment ####################

datex<- subset(dat3, dat3$pvchk==1)

var_list = list(datex$pv1, datex$pv2)

pvex1 <- lapply(var_list,
                 function(x) broom::tidy(lm(x~apstot9*pvcond,
                                            data = datex, na.action = na.exclude))) 
pvex2 <- lapply(var_list,
               function(x) broom::tidy(lm(x~otot9*pvcond+atot9*pvcond+mtot9*pvcond,
                                          data = datex, na.action = na.exclude))) 

pvex<- dplyr::bind_rows(pvex1,pvex2, .id = "dv") %>%
  mutate(.,
         conf.low = estimate - stats::qnorm(1 - (1 - .95) /
                                              2) * std.error,
         conf.high = estimate + stats::qnorm(1 - (1 - .95) /
                                               2) * std.error,
         cond = ifelse(term == "apstot9:pvcond6"|
                         term == "otot9:pvcond6"|
                         term == "pvcond6:atot9"|
                         term == "pvcond6:mtot9", "Murder",
                       ifelse(term == "apstot9:pvcond5"|
                                term == "otot9:pvcond5"|
                                term == "pvcond5:atot9"|
                                term == "pvcond5:mtot9", "Assault, DW",
                              ifelse(term == "apstot9:pvcond4"|
                                       term == "otot9:pvcond4"|
                                       term == "pvcond4:atot9"|
                                       term == "pvcond4:mtot9", "Arson",
                                     ifelse(term == "apstot9:pvcond3"|
                                              term == "otot9:pvcond3"|
                                              term == "pvcond3:atot9"|
                                              term == "pvcond3:mtot9", "Assault",
                                            ifelse(term == "apstot9:pvcond2"|
                                                     term == "otot9:pvcond2"|
                                                     term == "pvcond2:atot9"|
                                                     term == "pvcond2:mtot9", "Vandalism", NA))))),
         dv = ifelse(dv == 3, 1,
                     ifelse(dv == 4, 2, dv))
  ) %>%
  relabel_predictors(.,
                          "apstot9:pvcond6" = "APS",
                          "apstot9:pvcond5" = "APS",
                          "apstot9:pvcond4" = "APS",
                          "apstot9:pvcond3" = "APS",
                          "apstot9:pvcond2" = "APS",
                          "otot9:pvcond6" = "Othering",
                          "otot9:pvcond5" = "Othering",
                          "otot9:pvcond4" = "Othering",
                          "otot9:pvcond3" = "Othering",
                          "otot9:pvcond2" = "Othering",
                          "pvcond6:atot9" = "Aversion",
                          "pvcond5:atot9" = "Aversion",
                          "pvcond4:atot9" = "Aversion",
                          "pvcond3:atot9" = "Aversion",
                          "pvcond2:atot9" = "Aversion",
                          "pvcond6:mtot9" = "Moralization",
                          "pvcond5:mtot9" = "Moralization",
                          "pvcond4:mtot9" = "Moralization",
                          "pvcond3:mtot9" = "Moralization",
                          "pvcond2:mtot9" = "Moralization") %>%
  mutate(.,
         full = ifelse(term == "APS", 0, 1)
         )

pvex<- dplyr::filter(pvex, term == "APS" | term == "Othering" | term == "Aversion" | term == "Moralization")

pvex

my_colors = brewer.pal(n = 9, "Greens")[9:5]

fpvex1<- ggplot(subset(pvex, pvex$dv == 1), aes(x = estimate, 
                                                xmin = conf.low, 
                                                xmax = conf.high, 
                                                y = factor(term, levels = c("Moralization",
                                                                            "Aversion",
                                                                            "Othering",
                                                                            "APS")),
                                                color = factor(cond, levels = c(
                                                  "Murder",
                                                  "Assault, DW",
                                                  "Arson",
                                                  "Assault",
                                                  "Vandalism")),
                                                shape = factor(cond, levels = c(
                                                  "Murder",
                                                  "Assault, DW",
                                                  "Arson",
                                                  "Assault",
                                                  "Vandalism")),
                                                fill = factor(cond, levels = c(
                                                  "Murder",
                                                  "Assault, DW",
                                                  "Arson",
                                                  "Assault",
                                                  "Vandalism"
                                                )))) + 
  geom_pointrangeh(position = position_dodge(width = .65), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(0,1))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Sentencing Length") +
  xlab("") + 
  ylab("") + 
  labs(color = "Condition",
       shape = "Condition",
       fill = "Condition") +
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_text(size = 7),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.text = element_text(size = 6),
    legend.title = element_text(size = 7)) +
  guides(shape = guide_legend(override.aes = list(size = 0.2), reverse = T),
         color = guide_legend(override.aes = list(size = 0.2), reverse = T),
         fill = guide_legend(override.aes = list(size = 0.2), reverse = T)
  ) + 
  scale_shape_manual(
    values = c(25,23,24,22,21)
  ) +
  scale_color_manual(values = my_colors) +
  scale_fill_manual(values = my_colors)
  #scale_color_grey(start = 0, end = 0.6) +
  #scale_fill_grey(start = 0, end = 0.6)

fpvex1

fpvex2<- ggplot(subset(pvex, pvex$dv == 2), aes(x = estimate, 
                         xmin = conf.low, 
                         xmax = conf.high, 
                         y = factor(term, levels = c("Moralization",
                                                     "Aversion",
                                                     "Othering",
                                                     "APS")),
                         color = factor(cond, levels = c(
                           "Murder",
                           "Assault, DW",
                           "Arson",
                           "Assault",
                           "Vandalism")),
                         shape = factor(cond, levels = c(
                           "Murder",
                           "Assault, DW",
                           "Arson",
                           "Assault",
                           "Vandalism")),
                         fill = factor(cond, levels = c(
                           "Murder",
                           "Assault, DW",
                           "Arson",
                           "Assault",
                           "Vandalism"
                         )))) + 
  geom_pointrangeh(position = position_dodge(width = .65), size = .5, fatten = 2) + 
  facet_grid(factor(full, levels = c(0,1))~
               factor(dv),
             scales = "free",
             space = "free_y") +
  geom_vline(xintercept = 0,
             colour = "black",
             linetype = 2,
             linewidth = .3) +
  ggtitle("Support Pardon") +
  xlab("") + 
  ylab("") + 
  labs(color = "Condition",
       shape = "Condition",
       fill = "Condition") +
  theme(
    plot.title = element_text(hjust = .5, size = 8, face = "plain"),
    axis.text.x = element_text(size = 7),
    axis.text.y = element_blank(),
    strip.text = element_blank(),
    legend.key.size = unit(.6,"cm"),
    legend.key = element_rect(fill = "white"),
    legend.text = element_text(size = 6),
    legend.title = element_text(size = 7)) +
  guides(shape = guide_legend(override.aes = list(size = 0.2), reverse = T),
         color = guide_legend(override.aes = list(size = 0.2), reverse = T),
         fill = guide_legend(override.aes = list(size = 0.2), reverse = T)
         ) + 
  scale_shape_manual(
    values = c(25,23,24,22,21)
  ) +
  scale_color_manual(values = my_colors) +
  scale_fill_manual(values = my_colors)
  #scale_color_brewer(start = 0, end = 0.6) +
  #scale_fill_grey(start = 0, end = 0.6)

fpvex2

#### Figure 4 ####

Figure4<- fpvex1 + fpvex2 + plot_layout(guides = "collect")

Figure4

ggsave("Plots/Figure4.pdf",
       plot = Figure4,
       width = 6,
       height = 4,
       dpi = 1000,
       units = "in")

#Tables for Appendices ###########################

#### PID Extremity OL ####

m1 <- lapply(df_list,
             function(x) (lm(rpidex~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(rpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

s1F <- list(polr(fpidex~apstot9+age+ba+white+hisplat+male+inc,
                             data = dat1, na.action = na.exclude, method = c("logistic")))
s2F <- list(polr(fpidex~apstot9+age+ba+white+hisplat+male+inc,
            data = dat2, na.action = na.exclude, method = c("logistic")))
s3F <- list(polr(fpidex~apstot9+age+ba+white+hisplat+male+inc,
            data = dat3, na.action = na.exclude, method = c("logistic")))
s4F <- list(polr(fpidex~apstot9+age+ba+white+hisplat+male+inc,
            data = dat4, na.action = na.exclude, method = c("logistic")))

s1S <- list(polr(fpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                               data = dat1, na.action = na.exclude, method = c("logistic")))
s2S <- list(polr(fpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
            data = dat2, na.action = na.exclude, method = c("logistic")))
s3S <- list(polr(fpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
            data = dat3, na.action = na.exclude, method = c("logistic")))
s4S <- list(polr(fpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
            data = dat4, na.action = na.exclude, method = c("logistic")))

gaze1<-(list(c(m1[1], s1F, m2[1], s1S,
              m1[2], s2F, m2[2], s2S)))

gaze2<-(list(c(m1[3], s3F, m2[3], s3S,
              m1[4], s4F, m2[4], s4S)))

stargazer(gaze1,
          title = "Regression Results",            
          dep.var.labels = "PID Extremity", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          dep.var.labels = "PID Extremity", 
          column.labels = c("Study 3", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list, lapply,
             function(x) (lm(rpidex~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list, lapply,
             function(x) (lm(rpidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze1<-(list(c(m1$dat1[1], m1$dat1[2], m2$dat1[1], m2$dat1[2],
               m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2])))

gaze2<-(list(c(m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2],
               m1$dat4[1], m1$dat4[2], m2$dat4[1], m2$dat4[2])))

stargazer(gaze1,
          title = "Regression Results",            
          dep.var.labels = "PID Extremity", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          dep.var.labels = "PID Extremity", 
          column.labels = c("Study 3", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

  # Standardized Coeffs
m1 <- lapply(df_list,
             function(x) (lm(scale(rpidex)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(scale(rpidex)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat1, m2$dat1, m1$dat2, m2$dat2,
            m1$dat3, m2$dat3, m1$dat4, m2$dat4)

stargazer(gaze,
          dep.var.labels = "PID Extremity", 
          column.labels = c("Study 1", "Study 2", "Study 3", "Study 4W1"),
          column.separate = c(2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### PID Social Identity ####

m1 <- lapply(df_list,
             function(x) (lm(idtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(idtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1[1], m2[1],
              m1[2], m2[2],
              m1[3], m2[3],
              m1[4], m2[4])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Partisan Social Identity", 
          column.labels = c("Study 1", "Study 2", "Study 3", "Study 4 W1"),
          column.separate = c(2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list, lapply,
             function(x) (lm(idtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list, lapply,
             function(x) (lm(idtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze1<-(list(c(m1$dat1[1], m1$dat1[2], m2$dat1[1], m2$dat1[2],
               m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2])))

gaze2<-(list(c(m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2],
               m1$dat4[1], m1$dat4[2], m2$dat4[1], m2$dat4[2])))

stargazer(gaze1,
          title = "Regression Results",            
          dep.var.labels = "Partisan Social Identity", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          dep.var.labels = "Partisan Social Identity", 
          column.labels = c("Study 3", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
m1 <- lapply(df_list,
             function(x) (lm(scale(idtot)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(scale(idtot)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat1, m2$dat1, m1$dat2, m2$dat2,
            m1$dat3, m2$dat3, m1$dat4, m2$dat4)

stargazer(gaze,
          dep.var.labels = "Partisan Social Identity", 
          column.labels = c("Study 1", "Study 2", "Study 3", "Study 4W1"),
          column.separate = c(2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Ideology Extremity OL ####

m1 <- lapply(df_list,
             function(x) (lm(ridex~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(ridex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

s1F <- list(polr(fidex~apstot9+age+ba+white+hisplat+male+inc,
                 data = dat1, na.action = na.exclude, method = c("logistic")))
s2F <- list(polr(fidex~apstot9+age+ba+white+hisplat+male+inc,
                 data = dat2, na.action = na.exclude, method = c("logistic")))
s3F <- list(polr(fidex~apstot9+age+ba+white+hisplat+male+inc,
                 data = dat3, na.action = na.exclude, method = c("logistic")))
s4F <- list(polr(fidex~apstot9+age+ba+white+hisplat+male+inc,
                 data = dat4, na.action = na.exclude, method = c("logistic")))

s1S <- list(polr(fidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                 data = dat1, na.action = na.exclude, method = c("logistic")))
s2S <- list(polr(fidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                 data = dat2, na.action = na.exclude, method = c("logistic")))
s3S <- list(polr(fidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                 data = dat3, na.action = na.exclude, method = c("logistic")))
s4S <- list(polr(fidex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                 data = dat4, na.action = na.exclude, method = c("logistic")))

gaze1<-(list(c(m1[1], s1F, m2[1], s1S,
               m1[2], s2F, m2[2], s2S)))

gaze2<-(list(c(m1[3], s3F, m2[3], s3S,
               m1[4], s4F, m2[4], s4S)))

stargazer(gaze1,
          title = "Regression Results",            
          dep.var.labels = "Ideological Extremity", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          dep.var.labels = "Ideological Extremity", 
          column.labels = c("Study 3", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list, lapply,
             function(x) (lm(ridex~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list, lapply,
             function(x) (lm(ridex~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze1<-(list(c(m1$dat1[1], m1$dat1[2], m2$dat1[1], m2$dat1[2],
              m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2])))

gaze2<-(list(c(m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2],
              m1$dat4[1], m1$dat4[2], m2$dat4[1], m2$dat4[2])))

stargazer(gaze1,
          title = "Regression Results",            
          dep.var.labels = "Ideological Extremity", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          dep.var.labels = "Ideological Extremity", 
          column.labels = c("Study 3", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
m1 <- lapply(df_list,
             function(x) (lm(scale(ridex)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list,
             function(x) (lm(scale(ridex)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat1, m2$dat1, m1$dat2, m2$dat2,
            m1$dat3, m2$dat3, m1$dat4, m2$dat4)

stargazer(gaze,
          dep.var.labels = "Ideological Exremity", 
          column.labels = c("Study 1", "Study 2", "Study 3", "Study 4W1"),
          column.separate = c(2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Political Knowledge ####

m1 <- lapply(df_list[c(3,4)],
             function(x) (lm(pktot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(3,4)],
             function(x) (lm(pktot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1[1], m2[1],
              m1[2], m2[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Knowledge", 
          column.labels = c("Study 1", "Study 2"),
          column.separate = c(2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list[c(3,4)], lapply,
             function(x) (lm(pktot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list[c(3,4)], lapply,
             function(x) (lm(pktot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2],
              m1$dat4[1], m1$dat4[2], m2$dat4[1], m2$dat4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Knowledge", 
          column.labels = c("Study 3", "Study 4W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
m1 <- lapply(df_list[c(3,4)],
             function(x) (lm(scale(pktot)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(3,4)],
             function(x) (lm(scale(pktot)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat3, m2$dat3, m1$dat4, m2$dat4)

stargazer(gaze,
          dep.var.labels = "Political Knowledge", 
          column.labels = c("Study 3", "Study 4W1"),
          column.separate = c(2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Warmth Bias ####

m1 <- lapply(df_list[c(2,3,4)],
             function(x) (lm(wbias~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3,4)],
             function(x) (lm(wbias~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1[1], m2[1],
              m1[2], m2[2],
              m1[3], m2[3])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Warmth Bias", 
          column.labels = c("Study 2", "Study 3", "Study 4 W1"),
          column.separate = c(2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list[c(2,3,4)], lapply,
             function(x) (lm(wbias~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list[c(2,3,4)], lapply,
             function(x) (lm(wbias~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2],
              m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2],
              m1$dat4[1], m1$dat4[2], m2$dat4[1], m2$dat4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Warmth Bias", 
          column.labels = c("Study 2", "Study 3", "Study 4 W1"),
          column.separate = c(4,4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
m1 <- lapply(df_list[c(2,3,4)],
             function(x) (lm(scale(wbias)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3,4)],
             function(x) (lm(scale(wbias)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat2, m2$dat2, m1$dat3, m2$dat3, m1$dat4, m2$dat4)

stargazer(gaze,
          dep.var.labels = "Warmth Bias", 
          column.labels = c("Study 2", "Study 3", "Study 4W1"),
          column.separate = c(2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Trait Rating Bias ####

m1 <- lapply(df_list[c(2,3)],
             function(x) (lm(trtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3)],
             function(x) (lm(trtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1[1], m2[1],
              m1[2], m2[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Trait Rating Bias", 
          column.labels = c("Study 2", "Study 3"),
          column.separate = c(2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

m1 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(trtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(trtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

gaze<-(list(c(m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2],
              m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Trait Rating Bias", 
          column.labels = c("Study 2", "Study 3"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
m1 <- lapply(df_list[c(2,3)],
             function(x) (lm(scale(trtot)~scale(apstot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3)],
             function(x) (lm(scale(trtot)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 
gaze<- list(m1$dat2, m2$dat2, m1$dat3, m2$dat3)

stargazer(gaze,
          dep.var.labels = "Trait Rating Bias", 
          column.labels = c("Study 2", "Study 3"),
          column.separate = c(2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Anti-Democratic Attitudes Wbias####

var_list = list(dat3$ANESdnorm, dat3$uncandtot, dat3$pspitetot, dat3$artot)

m1 <- lapply(df_list[c(2,3)],
             function(x) (lm(rotgtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3)],
             function(x) (lm(rotgtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

m3 <- lapply(var_list,
             function(x) (lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                             data = dat3, na.action = na.exclude)))
m4 <- lapply(var_list,
             function(x) (lm(x~otot9+wbias+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = dat3, na.action = na.exclude))) 

gaze1<-(list(c(m1[1], m2[1],
              m1[2], m2[2],
              m3[1], m4[1])))

gaze2<-(list(c(m3[2], m4[2],
               m3[3], m4[3],
               m3[4], m4[4])))

stargazer(gaze1,
          title = "Regression Results",            
          column.labels = c("rotg S2", "rotg S3", "dnorms S3"),
          column.separate = c(2,2,2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          column.labels = c("antidem cand S3", "pspite", "authrule"),
          column.separate = c(2,2,2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

ptvar_list = split(dat3[c("ANESdnorm", "uncandtot", "pspitetot", "artot")],
                   dat3$pid01)

m1 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(rotgtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(rotgtot~otot9+atot9+mtot9+wbias+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

m3 <- lapply(ptvar_list[["0"]], 
             function(x) (lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==0), na.action = na.exclude)))
m4 <- lapply(ptvar_list[["0"]], 
             function(x) (lm(x~otot9+wbias+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==0), na.action = na.exclude))) 

m5 <- lapply(ptvar_list[["1"]], 
             function(x) (lm(x~apstot9+wbias+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==1), na.action = na.exclude)))
m6 <- lapply(ptvar_list[["1"]], 
             function(x) (lm(x~otot9+wbias+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==1), na.action = na.exclude))) 

gaze1<-(list(c(m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2],
               m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2])))

gaze2<-(list(c(m3[1], m5[1], m4[1], m6[1],
               m3[2], m5[2], m4[2], m6[2])))

gaze3<-(list(c(m3[3], m5[3], m4[3], m6[3],
               m3[4], m5[4], m4[4], m6[4])))

stargazer(gaze1,
          title = "Regression Results",            
          column.labels = c("rotg S2", "rotg S3"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          column.labels = c("dnorms S3", "antidem cand S3"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze3,
          title = "Regression Results",            
          column.labels = c("pspite", "authrule"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

# Standardized Coeffs
var_list = list(dat3$ANESdnorm, dat3$uncandtot, dat3$pspitetot, dat3$artot)

m1 <- lapply(df_list[c(2,3)],
             function(x) (lm(scale(rotgtot)~scale(apstot9)+scale(wbias)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3)],
             function(x) (lm(scale(rotgtot)~scale(otot9)+scale(atot9)+scale(mtot9)+scale(wbias)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = x, na.action = na.exclude))) 

m3 <- lapply(var_list,
             function(x) (lm(scale(x)~scale(apstot9)+scale(wbias)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = dat3, na.action = na.exclude)))
m4 <- lapply(var_list,
             function(x) (lm(scale(x)~scale(otot9)+scale(wbias)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                             data = dat3, na.action = na.exclude))) 

gaze1<-(list(c(m1[1], m2[1],
               m1[2], m2[2],
               m3[1], m4[1])))

gaze2<-(list(c(m3[2], m4[2],
               m3[3], m4[3],
               m3[4], m4[4])))


stargazer(gaze1,
          column.labels = c("rotg S2", "rotg S3", "dnorms S3"),
          column.separate = c(2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          column.labels = c("antidem cand S3", "pspite", "authrule"),
          column.separate = c(2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Anti-Democratic Attitudes No Wbias####

var_list = list(dat3$ANESdnorm, dat3$uncandtot, dat3$pspitetot, dat3$artot)

m1 <- lapply(df_list[c(2,3)],
             function(x) (lm(rotgtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(df_list[c(2,3)],
             function(x) (lm(rotgtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

m3 <- lapply(var_list,
             function(x) (lm(x~apstot9+age+ba+white+hisplat+male+inc,
                             data = dat3, na.action = na.exclude)))
m4 <- lapply(var_list,
             function(x) (lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = dat3, na.action = na.exclude))) 

gaze1<-(list(c(m1[1], m2[1],
               m1[2], m2[2],
               m3[1], m4[1])))

gaze2<-(list(c(m3[2], m4[2],
               m3[3], m4[3],
               m3[4], m4[4])))

stargazer(gaze1,
          title = "Regression Results",            
          column.labels = c("rotg S2", "rotg S3", "dnorms S3"),
          column.separate = c(2,2,2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          column.labels = c("antidem cand S3", "pspite", "authrule"),
          column.separate = c(2,2,2,2,2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

ptvar_list = split(dat3[c("ANESdnorm", "uncandtot", "pspitetot", "artot")],
                   dat3$pid01)

m1 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(rotgtot~apstot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude)))
m2 <- lapply(pt_list[c(2,3)], lapply,
             function(x) (lm(rotgtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = x, na.action = na.exclude))) 

m3 <- lapply(ptvar_list[["0"]], 
             function(x) (lm(x~apstot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==0), na.action = na.exclude)))
m4 <- lapply(ptvar_list[["0"]], 
             function(x) (lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==0), na.action = na.exclude))) 

m5 <- lapply(ptvar_list[["1"]], 
             function(x) (lm(x~apstot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==1), na.action = na.exclude)))
m6 <- lapply(ptvar_list[["1"]], 
             function(x) (lm(x~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                             data = subset(dat3, dat3$pid01==1), na.action = na.exclude))) 

gaze1<-(list(c(m1$dat2[1], m1$dat2[2], m2$dat2[1], m2$dat2[2],
               m1$dat3[1], m1$dat3[2], m2$dat3[1], m2$dat3[2])))

gaze2<-(list(c(m3[1], m5[1], m4[1], m6[1],
               m3[2], m5[2], m4[2], m6[2])))

gaze3<-(list(c(m3[3], m5[3], m4[3], m6[3],
               m3[4], m5[4], m4[4], m6[4])))

stargazer(gaze1,
          title = "Regression Results",            
          column.labels = c("rotg S2", "rotg S3"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze2,
          title = "Regression Results",            
          column.labels = c("dnorms S3", "antidem cand S3"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

stargazer(gaze3,
          title = "Regression Results",            
          column.labels = c("pspite", "authrule"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Political Violence Tobit ####

pv1 <- lapply(df_list[c(2,4)],
              function(x) (lm(pvtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude)))
pv2 <- lapply(df_list[c(2,4)],
              function(x) (lm(pvtot~wbias+otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude))) 
pv3 <- lapply(df_list[c(2,4)],
              function(x) (tobit(pvtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude, left = 0)))
pv4 <- lapply(df_list[c(2,4)],
              function(x) (tobit(pvtot~wbias+otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                         data = x, na.action = na.exclude, left = 0)))

gaze<-(list(c(pv1[1], pv3[1], 
              pv2[1], pv4[1],
              pv1[2], pv3[2], 
              pv2[2], pv4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Violence", 
          column.labels = c("Study 2", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

pv1 <- lapply(df_list[c(2,4)],
              function(x) (lm(pvtot~apstot9+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude)))
pv2 <- lapply(df_list[c(2,4)],
              function(x) (lm(pvtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude))) 
pv3 <- lapply(df_list[c(2,4)],
              function(x) (tobit(pvtot~apstot9+age+ba+white+hisplat+male+inc,
                                 data = x, na.action = na.exclude, left = 0)))
pv4 <- lapply(df_list[c(2,4)],
              function(x) (tobit(pvtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                                 data = x, na.action = na.exclude, left = 0)))

gaze<-(list(c(pv1[1], pv3[1], 
              pv2[1], pv4[1],
              pv1[2], pv3[2], 
              pv2[2], pv4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Violence", 
          column.labels = c("Study 2", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))


pv1 <- lapply(pt_list[c(2,4)], lapply,
              function(x) (lm(pvtot~apstot9+wbias+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude)))
pv2 <- lapply(pt_list[c(2,4)], lapply,
              function(x) (lm(pvtot~wbias+otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude))) 

gaze<-(list(c(pv1$dat2[1], pv1$dat2[2], pv2$dat2[1], pv2$dat2[2], 
              pv1$dat4[1], pv1$dat4[2], pv2$dat4[1], pv2$dat4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Violence", 
          column.labels = c("Study 2", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

pv1 <- lapply(pt_list[c(2,4)], lapply,
              function(x) (lm(pvtot~apstot9+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude)))
pv2 <- lapply(pt_list[c(2,4)], lapply,
              function(x) (lm(pvtot~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
                              data = x, na.action = na.exclude))) 

gaze<-(list(c(pv1$dat2[1], pv1$dat2[2], pv2$dat2[1], pv2$dat2[2], 
              pv1$dat4[1], pv1$dat4[2], pv2$dat4[1], pv2$dat4[2])))

stargazer(gaze,
          title = "Regression Results",            
          dep.var.labels = "Political Violence", 
          column.labels = c("Study 2", "Study 4 W1"),
          column.separate = c(4,4),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

  # Standardized Coeffs

pv1 <- lapply(df_list[c(2,4)],
              function(x) (lm(scale(pvtot)~scale(apstot9)+scale(wbias)+scale(age)+ba+white+hisplat+male+scale(inc),
                              data = x, na.action = na.exclude)))
pv2 <- lapply(df_list[c(2,4)],
              function(x) (lm(scale(pvtot)~scale(wbias)+scale(otot9)+scale(atot9)+scale(mtot9)+scale(age)+ba+white+hisplat+male+scale(inc),
                              data = x, na.action = na.exclude))) 

gaze<- list(pv1$dat2, pv2$dat2, pv1$dat4, pv2$dat4)

stargazer(gaze,
          dep.var.labels = c("Partisan Violence", "Political Violence"), 
          column.labels = c("Study 2", "Study 4W1"),
          column.separate = c(2,2),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Full Political Violence Experiment ####
datex<- subset(dat3, dat3$pvchk==1)

var_list = list(datex$pv1, datex$pv2)

ptvar_list = split(datex[c("pv1", "pv2")],
                   datex$pid01)

pvex1 <- lapply(var_list,
                function(x) lm(x~apstot9*pvcond,
                                           data = datex, na.action = na.exclude))
pvex2 <- lapply(var_list,
                function(x) lm(x~otot9*pvcond+atot9*pvcond+mtot9*pvcond,
                                           data = datex, na.action = na.exclude))
pvex3 <- lapply(var_list,
                function(x) lm(x~pvcond,
                               data = datex, na.action = na.exclude))
gaze<- list(c(pvex3[1], pvex1[1], pvex2[1],
              pvex3[2], pvex1[2], pvex2[2]))

stargazer(gaze,
          title = "Regression Results",   
          dep.var.labels = c("Sentence Length", "Support Pardon"),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

pvex1 <- lapply(ptvar_list[["0"]],
                function(x) lm(x~apstot9*pvcond,
                               data = subset(datex, datex$pid01==0), na.action = na.exclude))
pvex2 <- lapply(ptvar_list[["1"]],
                function(x) lm(x~apstot9*pvcond,
                               data = subset(datex, datex$pid01==1), na.action = na.exclude))
pvex3 <- lapply(ptvar_list[["0"]],
                function(x) lm(x~otot9*pvcond+atot9*pvcond+mtot9*pvcond,
                               data = subset(datex, datex$pid01==0), na.action = na.exclude))
pvex4 <- lapply(ptvar_list[["1"]],
                function(x) lm(x~otot9*pvcond+atot9*pvcond+mtot9*pvcond,
                               data = subset(datex, datex$pid01==1), na.action = na.exclude))
gaze<- list(c(pvex1[1], pvex2[1], pvex3[1], pvex4[1],
              pvex1[2], pvex2[2], pvex3[2], pvex4[2]))

stargazer(gaze,
          title = "Regression Results",   
          dep.var.labels = c("Sentence Length", "Support Pardon"),
          column.labels = c("Study 2", "Study 4 W1"),
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Prereg-Need For Clorsure ####

nfc1<- list(lm(apstot9~nfctot+age+ba+white+hisplat+male+inc,
          data = dat3, na.action = na.exclude))
nfc2<- list(lm(apstot9~nfctot*pktot+age+ba+white+hisplat+male+inc,
          data = dat3, na.action = na.exclude))
nfc3<- list(lm(apstot9~nfctot*pktot*pid01+age+ba+white+hisplat+male+inc,
          data = dat3, na.action = na.exclude))

gaze<-(list(c(nfc1, nfc2, nfc3)))

stargazer(gaze,
          title = "Regression Results",            
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))

#### Prereg-Political Interest ####

pi1<- list(lm(rpi~apstot9+age+ba+white+hisplat+male+inc,
             data = dat3, na.action = na.exclude))
pi2<- list(lm(rpi~otot9+atot9+mtot9+age+ba+white+hisplat+male+inc,
             data = dat3, na.action = na.exclude))

gaze<- list(c(pi1, pi2))

stargazer(gaze,
          title = "Regression Results",            
          align = T,
          digits = 2,
          font.size = "scriptsize",
          style = "ajps",
          float.env = "table",
          keep.stat = "n",
          model.numbers = F,
          star.cutoffs = c(0.05, 0.01, .001))


